package com.aps.algorithm.heuristic.genetic.dto;

import cn.hutool.core.util.SerializeUtil;
import com.aps.algorithm.heuristic.genetic.model.Gene;
import com.aps.common.model.genetic.OrderProcess;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @Author nbZhuozh
 * @Date 2025-09-09  09:51
 *
 * 基因：【订单-工序】级
 * 编码规则：所属订单code + 工序code
 **/
@Data
@NoArgsConstructor
public class ApsOperationDto extends Gene implements Serializable {

    private OrderProcess orderProcess;

    @Override
    public String generatorGenCode() {
        /**
         * NOTES 基因编码维度为： 订单id + 工序顺序
         */
        return orderProcess.getOrderId() + "-" + orderProcess.getSequence();
    }

    public ApsOperationDto(OrderProcess orderProcess) {
        this.orderProcess = orderProcess;
        super.setGeneCode();
    }


    public static List<ApsOperationDto> build(List<OrderProcess> orderProcesses) {
        if(orderProcesses != null) {
            List<ApsOperationDto> dtos = new ArrayList<>();
            orderProcesses.forEach(op -> dtos.add(new ApsOperationDto(op)));
            return dtos;
        }
        return Collections.emptyList();
    }

    public static ApsOperationDto build(OrderProcess orderProcess) {
        return new ApsOperationDto(orderProcess);
    }



    public ApsOperationDto deepCopy() {
        return SerializeUtil.clone(this);
//        this.setGeneCode();
//        return this;
    }
}
